<!-- build time:Tue Dec 17 2019 19:26:45 GMT+0800 (GMT+08:00) --><!doctype html><html class="theme-next mist" lang="zh-Hans"><head><meta name="generator" content="Hexo 3.8.0"><meta name="google-site-verification" content="7Tau9WyVgxnsEY9oYedu9g0U6_8akOX3wiKbaYcrg9A"><meta name="baidu-site-verification" content="EVwLiaxdxX"><link href="/css/xps13.css" rel="stylesheet" type="text/css"><link href="/css/message.css" rel="stylesheet" type="text/css"><script type="text/javascript" src="/js/jquery-1.11.3.min.js"></script><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css"><meta name="keywords" content="Nginx,"><link rel="alternate" href="/atom.xml" title="MrBird" type="application/atom+xml"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1"><meta name="description" content="下载NginxNginx官网：http://nginx.org/en/download.html。网页提供了Nginx三种版本下载：开发版（Mainline Version）、稳定版（Stable Version）和过期版（Legacy Version）。Nignx提供Linux和Windows版本，这里使用的是Linux版本。此外，http://nginx.org/download/提供了所有版"><meta name="keywords" content="Nginx"><meta property="og:type" content="article"><meta property="og:title" content="Nginx安装与部署"><meta property="og:url" content="http://mrbird.cc/Nginx install deploy.html"><meta property="og:site_name" content="MrBird"><meta property="og:description" content="下载NginxNginx官网：http://nginx.org/en/download.html。网页提供了Nginx三种版本下载：开发版（Mainline Version）、稳定版（Stable Version）和过期版（Legacy Version）。Nignx提供Linux和Windows版本，这里使用的是Linux版本。此外，http://nginx.org/download/提供了所有版"><meta property="og:locale" content="zh-Hans"><meta property="og:image" content="http://mrbird.cc/img/mrbird_photo_20171026150431.png"><meta property="og:updated_time" content="2019-10-28T12:14:46.255Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="Nginx安装与部署"><meta name="twitter:description" content="下载NginxNginx官网：http://nginx.org/en/download.html。网页提供了Nginx三种版本下载：开发版（Mainline Version）、稳定版（Stable Version）和过期版（Legacy Version）。Nignx提供Linux和Windows版本，这里使用的是Linux版本。此外，http://nginx.org/download/提供了所有版"><meta name="twitter:image" content="http://mrbird.cc/img/mrbird_photo_20171026150431.png"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/",scheme:"Mist",sidebar:{position:"left",display:"always",offset:12,offset_float:0,b2t:!1,scrollpercent:!1},fancybox:!1,motion:!1}</script><title>Nginx安装与部署 | MrBird</title></head><body ondragstart="return!1" class="animsition" lang="zh-Hans" style="overflow-x:hidden;padding-right:280px"><script type="text/javascript" src="/js/mo.min.js"></script><style>@media (min-width:768px) and (max-width:991px){body .header-innerr{width:700px!important}}.header-innerr{margin:0 auto;padding:100px 0 70px;width:880px}@media (min-width:1600px){.container .header-innerr{width:1200px}}.header-innerr{position:relative}.header-innerr{padding:20px 0 0}.header-innerr:after,.header-innerr:before{content:" ";display:table}.header-innerr:after{clear:both}@media (max-width:767px){.header-innerr{width:auto;padding:10px;margin-bottom:-20px}}</style><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><header id="header" class="header"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><link href="https://fonts.font.im/css?family=Merienda" rel="stylesheet"><div class="custom-logo-site-title"><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title" style="font-family:Merienda;font-size:1.3rem">MrBird</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle"></p></div><div class="site-nav-toggle"><button><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section">HOME</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section">ARCHIVES</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section">TAGS</a></li><li class="menu-item menu-item-friends"><a href="/friends/" rel="section">FRIENDS</a></li><div class="sidebar-toggle" style="display:none"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="Search" spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav></div><div class="header-innerr"><div class="note info" style="margin:0;letter-spacing:.15px">🐤手把手教你搭建<strong>Spring Cloud微服务权限系统</strong>（从零到部署）：<a style="color:#40dab2;font-weight:600" href="https://www.kancloud.cn/mrbird/spring-cloud" target="_blank">https://www.kancloud.cn/mrbird/spring-cloud</a></div></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><link itemprop="mainEntityOfPage" href="http://mrbird.cc/Nginx install deploy.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="MrBird"><meta itemprop="description" content=""><meta itemprop="image" content="/images/blogImage.jpg"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="MrBird"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">Nginx安装与部署</h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">Posted on</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-15T09:51:45+08:00">2017-10-15 </time></span><span></span> <span class="post-meta-divider">|</span> <span class="page-pv"><i class="fa fa-laptop"></i>&nbsp;&nbsp;Visit count <span class="busuanzi-value" id="busuanzi_value_page_pv"></span></span></div></header><div class="post-body" itemprop="articleBody"><h2 id="下载Nginx"><a href="#下载Nginx" class="headerlink" title="下载Nginx"></a>下载Nginx</h2><p>Nginx官网：<a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">http://nginx.org/en/download.html</a>。网页提供了Nginx三种版本下载：开发版（Mainline Version）、稳定版（Stable Version）和过期版（Legacy Version）。Nignx提供Linux和Windows版本，这里使用的是Linux版本。此外，<a href="http://nginx.org/download/" target="_blank" rel="noopener">http://nginx.org/download/</a>提供了所有版本的Nginx下载。</p><p>Nginx源码的编译需要GCC编译器：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># gcc --version</span></span><br><span class="line"><span class="attribute">gcc</span> (Ubuntu <span class="number">5</span>.<span class="number">4</span>.<span class="number">0</span>-6ubuntu1~<span class="number">16</span>.<span class="number">04</span>.<span class="number">4</span>) <span class="number">5</span>.<span class="number">4</span>.<span class="number">0</span> <span class="number">20160609</span></span><br><span class="line">Copyright (C) <span class="number">2015</span> Free Software Foundation, Inc.</span><br><span class="line">This is free software; <span class="attribute">see</span> the source for copying conditions.  There is NO</span><br><span class="line">warranty; <span class="attribute">not</span> even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</span><br></pre></td></tr></table></figure><p></p><a id="more"></a><p>截止2017年10月15日，Nginx最新稳定版为1.12.2，下载并解压：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># mkdir nginx-download</span></span><br><span class="line"><span class="comment"># cd nginx-download/</span></span><br><span class="line"><span class="comment"># wget http://nginx.org/download/nginx-1.12.2.tar.gz</span></span><br><span class="line"><span class="comment"># tar -zxvf nginx-1.12.2.tar.gz </span></span><br><span class="line"><span class="comment"># cd nginx-1.12.2</span></span><br><span class="line"><span class="comment"># ll</span></span><br><span class="line"><span class="attribute">total</span> <span class="number">732</span></span><br><span class="line">drwxr-xr-x <span class="number">8</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">17</span> <span class="number">21</span>:<span class="number">16</span> ./</span><br><span class="line">drwxr-xr-x <span class="number">3</span> root root   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> ../</span><br><span class="line">-rw-r--r-- <span class="number">1</span> <span class="number">1001</span> <span class="number">1001</span> <span class="number">278202</span> Oct <span class="number">17</span> <span class="number">21</span>:<span class="number">16</span> CHANGES</span><br><span class="line">-rw-r--r-- <span class="number">1</span> <span class="number">1001</span> <span class="number">1001</span> <span class="number">423948</span> Oct <span class="number">17</span> <span class="number">21</span>:<span class="number">16</span> CHANGES.ru</span><br><span class="line">-rw-r--r-- <span class="number">1</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">1397</span> Oct <span class="number">17</span> <span class="number">21</span>:<span class="number">16</span> LICENSE</span><br><span class="line">-rw-r--r-- <span class="number">1</span> <span class="number">1001</span> <span class="number">1001</span>     <span class="number">49</span> Oct <span class="number">17</span> <span class="number">21</span>:<span class="number">16</span> README</span><br><span class="line">drwxr-xr-x <span class="number">6</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> auto/</span><br><span class="line">drwxr-xr-x <span class="number">2</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> conf/</span><br><span class="line">-rwxr-xr-x <span class="number">1</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">2481</span> Oct <span class="number">17</span> <span class="number">21</span>:<span class="number">16</span> configure*</span><br><span class="line">drwxr-xr-x <span class="number">4</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> contrib/</span><br><span class="line">drwxr-xr-x <span class="number">2</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> html/</span><br><span class="line">drwxr-xr-x <span class="number">2</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> man/</span><br><span class="line">drwxr-xr-x <span class="number">9</span> <span class="number">1001</span> <span class="number">1001</span>   <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">05</span> src/</span><br></pre></td></tr></table></figure><p></p><ul><li><strong>src</strong>目录下存放了Nginx的源代码；</li><li><strong>man</strong>目录下存放了Nginx的帮助文档；</li><li><strong>html</strong>目录存放了两个HTML文件，分别为Nginx欢迎页和异常页面；</li><li><strong>logs</strong>目录用于存放Nginx运行日志；</li><li><strong>auto</strong>目录存放了大量的脚本文件，和configure脚本有关；</li><li><strong>configure</strong>文件为Nginx的自动脚本程序。</li></ul><h2 id="Nginx编译与安装"><a href="#Nginx编译与安装" class="headerlink" title="Nginx编译与安装"></a>Nginx编译与安装</h2><p>在解压路径下，运行命令<code>./configure --prefix=/nginx</code>（<code>configure</code>脚本支持的选项可参考附录）配置Nginx的安装目录并生成Makefile文件：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./configure --prefix=/nginx</span></span><br><span class="line">...</span><br><span class="line"><span class="attribute">Configuration</span> summary</span><br><span class="line">  + using system PCRE library</span><br><span class="line">  + OpenSSL library is not used</span><br><span class="line">  + using system zlib library</span><br><span class="line"></span><br><span class="line">  nginx path prefix: <span class="string">"/nginx"</span></span><br><span class="line">  nginx binary file: <span class="string">"/nginx/sbin/nginx"</span></span><br><span class="line">  nginx modules path: <span class="string">"/nginx/modules"</span></span><br><span class="line">  nginx configuration prefix: <span class="string">"/nginx/conf"</span></span><br><span class="line">  nginx configuration file: <span class="string">"/nginx/conf/nginx.conf"</span></span><br><span class="line">  nginx pid file: <span class="string">"/nginx/logs/nginx.pid"</span></span><br><span class="line">  nginx <span class="literal">error</span> log file: <span class="string">"/nginx/logs/error.log"</span></span><br><span class="line">  nginx http access log file: <span class="string">"/nginx/logs/access.log"</span></span><br><span class="line">  nginx http client request body temporary files: <span class="string">"client_body_temp"</span></span><br><span class="line">  nginx http proxy temporary files: <span class="string">"proxy_temp"</span></span><br><span class="line">  nginx http fastcgi temporary files: <span class="string">"fastcgi_temp"</span></span><br><span class="line">  nginx http uwsgi temporary files: <span class="string">"uwsgi_temp"</span></span><br><span class="line">  nginx http scgi temporary files: <span class="string">"scgi_temp"</span></span><br></pre></td></tr></table></figure><p></p><p>过程中可能出现一些依赖库缺失问题，可参考下面的常见问题。生成了Makefile文件后，使用<code>make</code>命令进行编译：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># make</span></span><br><span class="line"><span class="attribute">make</span> -f objs/Makefile</span><br><span class="line">make[<span class="number">1</span>]: Entering directory <span class="string">'/temp/nginx-download/nginx-1.12.2'</span></span><br><span class="line">cc -c -pipe  -O -W -Wall -Wpointer-arith -W<span class="literal">no</span>-unused-parameter -W<span class="literal">error</span> -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \</span><br><span class="line">	-o objs/src/core/nginx.o \</span><br><span class="line">	src/core/nginx.c</span><br><span class="line">cc -c -pipe  -O -W -Wall -Wpointer-arith -W<span class="literal">no</span>-unused-parameter -W<span class="literal">error</span> -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \</span><br><span class="line">...</span><br><span class="line">objs/src/http/modules/ngx_http_upstream_keepalive_module.o \</span><br><span class="line">objs/src/http/modules/ngx_http_upstream_zone_module.o \</span><br><span class="line">objs/ngx_modules.o \</span><br><span class="line">-ldl -lpthread -lcrypt -lpcre -lz \</span><br><span class="line">-Wl,-E</span><br><span class="line">sed -e <span class="string">"s|%%PREFIX%%|/nginx|"</span> \</span><br><span class="line">	-e <span class="string">"s|%%PID_PATH%%|/nginx/logs/nginx.pid|"</span> \</span><br><span class="line">	-e <span class="string">"s|%%CONF_PATH%%|/nginx/conf/nginx.conf|"</span> \</span><br><span class="line">	-e <span class="string">"s|%%ERROR_LOG_PATH%%|/nginx/logs/error.log|"</span> \</span><br><span class="line">	&lt; man/nginx.<span class="number">8</span> &gt; objs/nginx.<span class="number">8</span></span><br><span class="line">make[<span class="number">1</span>]: Leaving directory <span class="string">'/temp/nginx-download/nginx-1.12.2'</span></span><br></pre></td></tr></table></figure><p></p><p>编译顺利完成后，接着使用<code>make install</code>命令进行安装：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># make install</span></span><br><span class="line"><span class="attribute">make</span> -f objs/Makefile install</span><br><span class="line">make[<span class="number">1</span>]: Entering directory <span class="string">'/temp/nginx-download/nginx-1.12.2'</span></span><br><span class="line">test -d <span class="string">'/nginx'</span> || mkdir -p <span class="string">'/nginx'</span></span><br><span class="line">test -d <span class="string">'/nginx/sbin'</span> \</span><br><span class="line">	|| mkdir -p <span class="string">'/nginx/sbin'</span></span><br><span class="line">...</span><br><span class="line">test -d <span class="string">'/nginx/logs'</span> \</span><br><span class="line">	|| mkdir -p <span class="string">'/nginx/logs'</span></span><br><span class="line">make[<span class="number">1</span>]: Leaving directory <span class="string">'/temp/nginx-download/nginx-1.12.2'</span></span><br></pre></td></tr></table></figure><p></p><p>将目录切换到/nginx下，并查看：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># cd /nginx/</span></span><br><span class="line"><span class="comment"># ll</span></span><br><span class="line"><span class="attribute">total</span> <span class="number">24</span></span><br><span class="line">drwxr-xr-x  <span class="number">6</span> root root <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">30</span> ./</span><br><span class="line">drwxr-xr-x <span class="number">26</span> root root <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">30</span> ../</span><br><span class="line">drwxr-xr-x  <span class="number">2</span> root root <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">30</span> conf/</span><br><span class="line">drwxr-xr-x  <span class="number">2</span> root root <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">30</span> html/</span><br><span class="line">drwxr-xr-x  <span class="number">2</span> root root <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">30</span> logs/</span><br><span class="line">drwxr-xr-x  <span class="number">2</span> root root <span class="number">4096</span> Oct <span class="number">26</span> <span class="number">14</span>:<span class="number">30</span> sbin/</span><br><span class="line"><span class="comment"># ls *</span></span><br><span class="line">conf:</span><br><span class="line">fastcgi.conf            koi-win             scgi_params</span><br><span class="line">fastcgi.conf.default    mime.types          scgi_params.default</span><br><span class="line">fastcgi_params          mime.types.default  uwsgi_params</span><br><span class="line">fastcgi_params.default  nginx.conf          uwsgi_params.default</span><br><span class="line">koi-utf                 nginx.conf.default  win-utf</span><br><span class="line"></span><br><span class="line">html:</span><br><span class="line">50x.html  index.html</span><br><span class="line"></span><br><span class="line">logs:</span><br><span class="line"></span><br><span class="line">sbin:</span><br><span class="line">nginx</span><br></pre></td></tr></table></figure><p></p><h2 id="Nginx的启停"><a href="#Nginx的启停" class="headerlink" title="Nginx的启停"></a>Nginx的启停</h2><h3 id="Nginx常用命令"><a href="#Nginx常用命令" class="headerlink" title="Nginx常用命令"></a>Nginx常用命令</h3><p>nginx命令所支持的选项有：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./sbin/nginx -h</span></span><br><span class="line"><span class="attribute">nginx</span> version: nginx/<span class="number">1</span>.<span class="number">12</span>.<span class="number">2</span></span><br><span class="line">Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]</span><br><span class="line"></span><br><span class="line">Options:</span><br><span class="line">  -?,-h         : this help</span><br><span class="line">  -v            : show version and exit</span><br><span class="line">  -V            : show version and configure options then exit</span><br><span class="line">  -t            : test configuration and exit</span><br><span class="line">  -T            : test configuration, dump it and exit</span><br><span class="line">  -q            : suppress non-<span class="literal">error</span> messages during configuration testing</span><br><span class="line">  -s signal     : send signal to a master process: stop, quit, reopen, reload</span><br><span class="line">  -p prefix     : set prefix path (default: /nginx/)</span><br><span class="line">  -c filename   : set configuration file (default: conf/nginx.conf)</span><br><span class="line">  -g directives : set global directives out of configuration file</span><br></pre></td></tr></table></figure><p></p><p><code>-v</code>选项用来显示Nginx服务器的版本号，<code>-V</code>选项除了显示版本号，还显示其编译情况：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./sbin/nginx -v</span></span><br><span class="line"><span class="attribute">nginx</span> version: nginx/<span class="number">1</span>.<span class="number">12</span>.<span class="number">2</span></span><br><span class="line"><span class="comment"># ./sbin/nginx -V</span></span><br><span class="line">nginx version: nginx/<span class="number">1</span>.<span class="number">12</span>.<span class="number">2</span></span><br><span class="line">built by gcc <span class="number">5</span>.<span class="number">4</span>.<span class="number">0</span> <span class="number">20160609</span> (Ubuntu <span class="number">5</span>.<span class="number">4</span>.<span class="number">0</span>-6ubuntu1~<span class="number">16</span>.<span class="number">04</span>.<span class="number">4</span>) </span><br><span class="line">configure arguments: --prefix=/nginx</span><br></pre></td></tr></table></figure><p></p><p><code>-t</code>选项用于检查Nginx服务器配置文件是否有语法错误：</p><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./sbin/nginx -t</span></span><br><span class="line">nginx: the configuration file /nginx/conf/nginx.conf syntax is ok</span><br><span class="line">nginx: configuration file /nginx/conf/nginx.conf test is successful</span><br></pre></td></tr></table></figure><p></p><p>等。</p><h3 id="Nginx启动"><a href="#Nginx启动" class="headerlink" title="Nginx启动"></a>Nginx启动</h3><p>启动Nginx服务器很简单，只需要运行sbin下的nginx脚本就行了：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./sbin/nginx </span></span><br><span class="line"><span class="comment"># ps -ef|grep nginx</span></span><br><span class="line"><span class="attribute">root</span>      <span class="number">74808</span>   <span class="number">1308</span>  <span class="number">0</span> <span class="number">14</span>:<span class="number">47</span> ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> nginx: master process ./sbin/nginx</span><br><span class="line">nobody    <span class="number">74809</span>  <span class="number">74808</span>  <span class="number">0</span> <span class="number">14</span>:<span class="number">47</span> ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> nginx: worker process</span><br><span class="line">root      <span class="number">74811</span>  <span class="number">71675</span>  <span class="number">0</span> <span class="number">14</span>:<span class="number">47</span> pts/<span class="number">4</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> grep --color=auto nginx</span><br></pre></td></tr></table></figure><p></p><p>可看到Nginx已经启动，包含了一个主进程（master process）和一个工作进程（worker process），主进程号为74808。启动Nginx服务后，也可以通过查看logs目录下的nginx.pid来查看主进程号：</p><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># cat logs/nginx.pid </span></span><br><span class="line">74808</span><br></pre></td></tr></table></figure><p></p><p>Nginx的默认端口号为80，在浏览器中输入<a href="localhost/index.html">localhost/index.html</a>查看是否启动成功：</p><p><img src="img/mrbird_photo_20171026150431.png" alt="mrbird_photo_20171026150431.png"></p><h3 id="Nginx停止"><a href="#Nginx停止" class="headerlink" title="Nginx停止"></a>Nginx停止</h3><p>停止Nginx服务可分为两种类型：</p><p>1.快速停止：立即停止当前Nginx服务正在处理的所有网络请求，马上丢弃连接，停止工作。相关命令为：<code>kill -TERM 进程号</code>或者<code>kill -INT 进程号</code>；</p><p>2.平缓停止：允许Nginx服务将当前的网络请求处理完毕，但不再接受新请求，之后关闭连接，停止工作。相关的命令为：<code>kill -QUIT 进程号</code>；</p><p>停止Nginx服务，采用快速停止方式：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># kill -TERM 74808</span></span><br><span class="line"><span class="comment"># ps -ef|grep nginx</span></span><br><span class="line"><span class="attribute">root</span>      <span class="number">74998</span>  <span class="number">71675</span>  <span class="number">0</span> <span class="number">15</span>:<span class="number">03</span> pts/<span class="number">4</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> grep --color=auto nginx</span><br></pre></td></tr></table></figure><p></p><h3 id="Nginx重启"><a href="#Nginx重启" class="headerlink" title="Nginx重启"></a>Nginx重启</h3><p>Nginx重启采用平滑重启的方式。Nginx服务进程号接收到重启信号后，先读取新的Nginx配置文件，如果配置语法正确，则启动新的Nginx服务，然后平缓的关闭旧的服务。如果配置语法错误，则继续采用旧的Nginx进程提供服务。</p><p>有两种方式进行平滑重启：</p><p>1.检查配置文件是否正确，如果正确进行重启：</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ./sbin/nginx -t</span></span><br><span class="line">nginx: the configuration file /nginx/conf/nginx.conf syntax is ok</span><br><span class="line">nginx: configuration file /nginx/conf/nginx.conf test is successful</span><br><span class="line"><span class="comment"># ./sbin/nginx -s reload</span></span><br></pre></td></tr></table></figure><p></p><p>2.<code>kill -HUP 主进程号</code>:</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># cat logs/nginx.pid </span></span><br><span class="line">75011</span><br><span class="line"><span class="comment"># kill -HUP 75011</span></span><br></pre></td></tr></table></figure><p></p><h2 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h2><h3 id="缺少依赖库"><a href="#缺少依赖库" class="headerlink" title="缺少依赖库"></a>缺少依赖库</h3><p><strong>缺少PCRE依赖库</strong></p><div class="note danger"><p>./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using –without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using –with-pcre=<path>option.</path></p></div>解决办法：<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">sudo</span> apt-get install libpcre3 libpcre3-dev</span><br></pre></td></tr></table></figure><p></p><p><strong>缺少zlib依赖库</strong></p><div class="note danger"><p>./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path>option.</path></p></div>解决办法：<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">sudo</span> apt-get install zlib1g-dev</span><br></pre></td></tr></table></figure><p></p><h3 id="其他问题"><a href="#其他问题" class="headerlink" title="其他问题"></a>其他问题</h3><p><strong>apt-get命令被占用</strong></p><div class="note danger"><p>E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?</p></div>解决办法：找到占用进程，然后kill：<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">ps</span> -A|grep apt</span><br><span class="line"> <span class="number">61213</span> ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">02</span> aptd</span><br><span class="line">kill -<span class="number">9</span> <span class="number">61213</span></span><br></pre></td></tr></table></figure><p></p><h2 id="附录"><a href="#附录" class="headerlink" title="附录"></a>附录</h2><p><em>注：由于渲染原因–实际为 <code>--</code>，如–prefix=…实际为 <code>--prefix=...</code></em></p><h3 id="configure开关选项"><a href="#configure开关选项" class="headerlink" title="configure开关选项"></a>configure开关选项</h3><table><tbody><tr><td style="word-break:break-all"><strong>选项&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td style="word-break:break-all"><strong>用法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td style="word-break:break-all"><strong>默认值</strong></td></tr><tr><td style="word-break:break-all;width:200px">–prefix=…</td><td style="word-break:break-all">指定安装Nginx的基础目录</td><td style="word-break:break-all">/usr/local/nginx, 注意：如果你在配置时使用了相对路径，则连接到基础目录。示例：指定–conf-path=conf/nginx.conf 则配置文件会在目录：/usr/local/nginx/conf/nginx.conf</td></tr><tr><td style="word-break:break-all">–sbin-path=…</td><td style="word-break:break-all">Nginx二进制文件安装的路径</td><td style="word-break:break-all">&lt;prefix&gt;/sbin/nginx</td></tr><tr><td style="word-break:break-all">–conf-path=…</td><td style="word-break:break-all">主要配置文件放置目录</td><td style="word-break:break-all">&lt;prefix&gt;/conf/nginx.conf</td></tr><tr><td style="word-break:break-all">–error-log-path=…</td><td style="word-break:break-all">错误日志存放的路径。错误日志在配置文件中须配置得非常正确，该路径只应用于你在配置文件中没有指定任何错误的日志指令时</td><td style="word-break:break-all">&lt;prefix&gt;/logs/error.log</td></tr><tr><td style="word-break:break-all">–pid-path=…</td><td style="word-break:break-all">指定Nginx的pid文件的路径。可以在配置文件中指定pid文件的路径，如果没有具体的指定，则使用在这里对该选项指定的该路径</td><td style="word-break:break-all">&lt;prefix&gt;/logs/nginx.pid注意：该pid文件是一个简单的文件文件，它包含进程的标识符。该文件应该放置在一个清晰可见的位置，以便其他应用程序能够很容易找到运行该程序的pid</td></tr><tr><td style="word-break:break-all">–lock-path=…</td><td style="word-break:break-all">锁文件（lock file）的存放路径。同样，该文件也可以在配置文件中指定，但是，如果在配置文件中没有指定，则使用该值</td><td style="word-break:break-all">&lt;prefix&gt;/logs/nginx.lock注意：锁文件允许其他应用程序确定是否一个程序在运行，就Nginx来说，它用于确定该进程没有被启动两次</td></tr><tr><td style="word-break:break-all">–with-perl_modules_path=…</td><td style="word-break:break-all">定义Perl模块的路径。如果需要包含另外的Perl模块，必须定义该参数</td><td></td></tr><tr><td style="word-break:break-all">–with-perl=…</td><td style="word-break:break-all">Perl二进制文件的路径。用于执行Perl脚本。如果想执行一个Perl脚本，必须设置该路径</td><td></td></tr><tr><td style="word-break:break-all">–http-log-path=…</td><td style="word-break:break-all">定义被访问文件的日志文件存放路径。该路径只用于在配置文件中没有定义访问日志的情况</td><td style="word-break:break-all">&lt;prefix&gt;/logs/access.log</td></tr><tr><td style="word-break:break-all">–http-client-body-temp-path=…</td><td style="word-break:break-all">该目录用于存储客户端请求产生的临时文件</td><td style="word-break:break-all">&lt;prefix&gt;/client_body_temp</td></tr><tr><td style="word-break:break-all">–http-proxy-temp-path=…</td><td style="word-break:break-all">该目录用于代理存储临时文件</td><td style="word-break:break-all">&lt;prefix&gt;/proxy_temp</td></tr><tr><td style="word-break:break-all">–http-fastcgi-temp-path=…</td><td style="word-break:break-all">指定用于HTTP FastCGI模块使用的临时文件的存放路径</td><td style="word-break:break-all">&lt;prefix&gt;/fastcgi_temp</td></tr><tr><td style="word-break:break-all">–builddir=…</td><td style="word-break:break-all">指定创建应用程序的位置</td><td></td></tr></tbody></table><h3 id="configure先決条件选项"><a href="#configure先決条件选项" class="headerlink" title="configure先決条件选项"></a>configure先決条件选项</h3><table><tbody><tr><td style="word-break:break-all;width:200px"><strong>编译选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-cc=…&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style="word-break:break-all">指定一个备用的C编译器的位置</td></tr><tr><td style="word-break:break-all">–with-cpp=…</td><td style="word-break:break-all">指定一个备用的C预处理器的位置</td></tr><tr><td style="word-break:break-all">–with-cc-opt=…</td><td style="word-break:break-all">定义额外的选项，然后在命令行传递给C编译器</td></tr><tr><td style="word-break:break-all">–with-ld-opt=…</td><td style="word-break:break-all">定义额外的选项，然后在命令行传递给C连接器</td></tr><tr><td style="word-break:break-all">–with-cpu-opt=…</td><td style="word-break:break-all">指定不同的目标处理器结构，可以是下列值：pentium，pentiumpro，pentium3，pentium4，athlon，opteron，sparc32，sparc64和ppc64</td></tr><tr><td style="word-break:break-all"><strong>PCRE选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–without-pcre</td><td style="word-break:break-all">不使用PCRE库。这个设置不推荐使用，因为它会移除对正则表达式的支持，从而使Rewrite模块失去作用。</td></tr><tr><td style="word-break:break-all">–with-pcre</td><td style="word-break:break-all">强制作用PCRE库</td></tr><tr><td style="word-break:break-all">–with-pcre=…</td><td style="word-break:break-all">允许指定PCRE库的源代码</td></tr><tr><td style="word-break:break-all">–with-pcre-opt=…</td><td style="word-break:break-all">用于建立PCRE库的另外的选项</td></tr><tr><td style="word-break:break-all"><strong>MD5选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-md5=…</td><td style="word-break:break-all">指定MD5库源代码的路径</td></tr><tr><td style="word-break:break-all">–with-md5-opt=…</td><td style="word-break:break-all">用于建立MD5库的另外选项</td></tr><tr><td style="word-break:break-all">–with-md5-asm</td><td style="word-break:break-all">为建MD5库使用汇编语言源代码</td></tr><tr><td style="word-break:break-all"><strong>SHA1选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-sha1=…</td><td style="word-break:break-all">指定SHA1库的源代码</td></tr><tr><td style="word-break:break-all">–with-sha1-opt=…</td><td style="word-break:break-all">用于建立SHA1库的另外选项</td></tr><tr><td style="word-break:break-all">–with-sha1-asm</td><td style="word-break:break-all">为建立SHA1库使用汇编语言源代码</td></tr><tr><td style="word-break:break-all"><strong>zlib选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-zlib=…</td><td style="word-break:break-all">指定zlib库的源代码</td></tr><tr><td style="word-break:break-all">–with-zlib-opt=…</td><td style="word-break:break-all">用于建立zlib库的另外的选项</td></tr><tr><td style="word-break:break-all">–with-zlib-asm=…</td><td style="word-break:break-all">使用汇编语言最大限度地优化下列目标结构：Pentium, pentiumpro</td></tr><tr><td style="word-break:break-all"><strong>OpenSSL选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-openssl=…</td><td style="word-break:break-all">指定OpenSSL库的源代码路径</td></tr><tr><td style="word-break:break-all">–with-openssl-opt=…</td><td style="word-break:break-all">为建立OpenSSL库的另外的选项</td></tr></tbody></table><h3 id="configure模块选项"><a href="#configure模块选项" class="headerlink" title="configure模块选项"></a>configure模块选项</h3><p>以下是Nginx默认开启的模块，可以使用表格中的命令来关闭相应模块：</p><table><tbody><tr><td style="word-break:break-all;width:336px"><strong>默认开启的模块&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td style="word-break:break-all"><strong>描述</strong></td></tr><tr><td style="word-break:break-all">–without-http-charset_module</td><td style="word-break:break-all">禁用Charset模块，该模块用于对网页重新编码</td></tr><tr><td style="word-break:break-all">–without-http-gzip_module</td><td style="word-break:break-all">禁用Gzip压缩模块</td></tr><tr><td style="word-break:break-all">–without-http_ssi_module</td><td style="word-break:break-all">禁用服务器端包含模块</td></tr><tr><td style="word-break:break-all">–without-http_access_module</td><td style="word-break:break-all">禁用访问模块，对于指定的IP段，允许访问配置</td></tr><tr><td style="word-break:break-all">–without-http_userid_module</td><td style="word-break:break-all">禁用用户ID模块。该模块为用户通过cookie验证身份</td></tr><tr><td style="word-break:break-all">–without-http_auth_basic_module</td><td style="word-break:break-all">禁用基本的认证模块</td></tr><tr><td style="word-break:break-all">–without-http_autoindex_module</td><td style="word-break:break-all">禁用自动索引模块</td></tr><tr><td style="word-break:break-all">–without-http_geo_module</td><td style="word-break:break-all">禁用Geo模块，该模块允许你定义依赖于IP地址段的变量</td></tr><tr><td style="word-break:break-all">–without-http_map_module</td><td style="word-break:break-all">禁用Map模块，该模块允许你声明map区段</td></tr><tr><td style="word-break:break-all">–without-http_referer_module</td><td style="word-break:break-all">禁用Referer控制模块</td></tr><tr><td style="word-break:break-all">–without-http_rewrite_module</td><td style="word-break:break-all">禁用Rewrite模块</td></tr><tr><td style="word-break:break-all">–without-http_proxy_module</td><td style="word-break:break-all">禁用代理模块。该模块用于向其他服务器传输请求</td></tr><tr><td style="word-break:break-all">–without-http_fastcgi_module</td><td style="word-break:break-all">禁用FastCGI模块。该模块是用于与FastCGI进程配合工作</td></tr><tr><td style="word-break:break-all">–without-http_memcached_module&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style="word-break:break-all">禁用Memcached模块。该模块是用于与memcached守护进程配合工作</td></tr><tr><td style="word-break:break-all">–without-http_limit_zone_module</td><td style="word-break:break-all">禁用Limit Zone模块。该模块是用于根据定义的zone来限制约束对资源的使用。</td></tr><tr><td style="word-break:break-all">–without-http_limit_req_module</td><td style="word-break:break-all">禁用Limit Requests模块。该模块允许你限制每个用户请求的总数</td></tr><tr><td style="word-break:break-all">–without-http_empty_gif_module</td><td style="word-break:break-all">禁用Empty Gif模块。该模块用于在内存中提供一个空白的GIF图像</td></tr><tr><td style="word-break:break-all">–without-http_browser_module</td><td style="word-break:break-all">禁用Browser模块。该模块用于解释用户代理字符串</td></tr><tr><td style="word-break:break-all">–without-http_upstream_ip_hash_module</td><td style="word-break:break-all">禁用Upstream模块。该模块用于配置负载均衡结构</td></tr></tbody></table><p>以下是Nginx默认关闭的模块，可以使用表格中的命令来开启相应模块：</p><table><tbody><tr><td style="word-break:break-all;width:336px"><strong>默认禁用的模块&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td><td style="word-break:break-all"><strong>描述</strong></td></tr><tr><td style="word-break:break-all">–with-http_ssl_module</td><td style="word-break:break-all">开启SSL模块，支持使用HTTPS协议的网页</td></tr><tr><td style="word-break:break-all">–with-http_realip_module</td><td style="word-break:break-all">开启Real IP的支持，该模块用于从客户请求的头数据中读取real IP地址</td></tr><tr><td style="word-break:break-all">–with-http_addition_module</td><td style="word-break:break-all">开启Addition模块，该模块允许你追加或前置数据（prepend data）到响应的主体部分</td></tr><tr><td style="word-break:break-all">–with-http_xslt_module</td><td style="word-break:break-all">开启XSLT模块的支持，该模块实现XSLT转化为XML文档</td></tr><tr><td style="word-break:break-all">–with-http_image_filter_module</td><td style="word-break:break-all">开启Image Filter模块，该模块是让你修改图像。注意：如果想编译该模块，需要在系统中安装libgd库</td></tr><tr><td style="word-break:break-all">–with-http_geoip_module</td><td style="word-break:break-all">开启GeoIP模块，该模块通过使用MaxMind’s GeoI 二进制数据库来获取客户端在地理上的分布。注意：如果希望编译该模块，需要在系统中安装libgeoip库。</td></tr><tr><td style="word-break:break-all">–with-http_sub_module</td><td style="word-break:break-all">开启Substitution模块，该模块用于在网页中替换文本</td></tr><tr><td style="word-break:break-all">–with-http_dav_module</td><td style="word-break:break-all">开启WebDAV模块</td></tr><tr><td style="word-break:break-all">–with-http_flv_module</td><td style="word-break:break-all">开启FLV模块，该模块用于专门处理.flv(flash视频)文件</td></tr><tr><td style="word-break:break-all">–with-http_gzip_static_module</td><td style="word-break:break-all">开启Gzip静态模块，该模块用于发送预压缩的文件</td></tr><tr><td style="word-break:break-all">–with-http_random_index_module</td><td style="word-break:break-all">开启Random Index模块。该模块用于挑选一个随机的文件作为该目录的index</td></tr><tr><td style="word-break:break-all">–with-http_secure_link_module</td><td style="word-break:break-all">开启Secure Link模块，该模块用于在URL中检测关键字的存在</td></tr><tr><td style="word-break:break-all">–with-http_stub_status_module</td><td style="word-break:break-all">开启Stub Status模块，该模块会产生一个服务器状态和信息页</td></tr><tr><td style="word-break:break-all">–with-google_perftools_module&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;</td><td style="word-break:break-all">开启google性能工具模块</td></tr></tbody></table><h3 id="其它configure选项"><a href="#其它configure选项" class="headerlink" title="其它configure选项"></a>其它configure选项</h3><table><tbody><tr><td style="word-break:break-all;width:336px"><strong>邮件服务代理</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-mail</td><td style="word-break:break-all">开启邮件服务代理（mail server proxy）模块，支持POP3，IMAP4和SMTP。该功能默认禁用</td></tr><tr><td style="word-break:break-all">–with-mail_ssl_module</td><td style="word-break:break-all">开启邮件代理服务对SSL的支持。该功能默认禁用</td></tr><tr><td style="word-break:break-all">–without-mail_pop3_module</td><td style="word-break:break-all">在邮件代理下禁用POP3功能。在开启邮件代理模块后该功能默认启用</td></tr><tr><td style="word-break:break-all">–without-mail_imap_module</td><td style="word-break:break-all">对邮件代理服务器禁用IMAP4模块，在开启邮件代理模块后该功能默认启用</td></tr><tr><td style="word-break:break-all">–without-mail_smtp_module</td><td style="word-break:break-all">对于邮件代理服务器禁用SMTP模块，在开启邮件代理模块后该功能默认启用</td></tr><tr><td style="word-break:break-all"><strong>事件管理</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–with-rtsig_module</td><td style="word-break:break-all">开启rtsig模块，使用rtsig作为事件通知机制</td></tr><tr><td style="word-break:break-all">–with-select_module</td><td style="word-break:break-all">开启select模块，使用select作为事件通知机制。默认情况下，该模块是开启的，除非系统有一种更好的方式发现——kqueue, epoll, rtsig 或 poll</td></tr><tr><td style="word-break:break-all">–without-select_module</td><td style="word-break:break-all">禁用select模块</td></tr><tr><td style="word-break:break-all">–with-poll_module</td><td style="word-break:break-all">开启poll模块，该模块使用poll作为事件通知机制。默认情况下，如果有效，该模块是开启的，除非系统上有一种更好的方式发现——kqueue, epoll或rtsig</td></tr><tr><td style="word-break:break-all">–without-poll_module</td><td style="word-break:break-all">禁用poll模块</td></tr><tr><td style="word-break:break-all"><strong>用户和组选项</strong></td><td style="word-break:break-all"></td></tr><tr><td style="word-break:break-all">–user=…</td><td style="word-break:break-all">指定启动Nginx进程的默认用户。这个设置仅用于在配置文件中省略user指令来指定用户的情况</td></tr><tr><td style="word-break:break-all">–group=…</td><td style="word-break:break-all">指定启动Nginx进程默认的用户组。这个设置仅用于在配置文件中省略使用group指令来指定用户的情况</td></tr><tr><td style="word-break:break-all"><strong>其它选项</strong></td><td></td></tr><tr><td style="word-break:break-all">–with-ipv6</td><td style="word-break:break-all">开启对IPv6的支持</td></tr><tr><td style="word-break:break-all">–without-http</td><td style="word-break:break-all">禁用HTTP服务</td></tr><tr><td style="word-break:break-all">–without-http-cache</td><td style="word-break:break-all">禁用HTTP缓冲功能</td></tr><tr><td style="word-break:break-all">–add-module=PATH</td><td style="word-break:break-all">通过指定的路径编译添加第三方模块。如果希望编译多个模块，那么该选项可以无限次使用</td></tr><tr><td style="word-break:break-all">–with-debug</td><td style="word-break:break-all">开启记录额外的调试信息</td></tr></tbody></table><script>$(".post-body a").not(".thispage").addClass("ignore-href").attr("target","_blank")</script></div><div></div><div><div style="padding:10px 0;margin:20px auto;width:90%;text-align:center;color:#878787"><div>请作者喝瓶肥宅水~</div><button id="rewardButton" style="margin-top:10px" disable="enable" onclick='var e=document.getElementById("QR");"none"===e.style.display?e.style.display="block":e.style.display="none"'><span style="height:46px;width:46px;line-height:46px;border-radius:50%;color:#fe5f55;font-weight:600;background:#ffd5be;border:none;box-shadow:0 4px 8px 0 rgba(255,213,190,.4)">￥</span></button><div id="QR" style="display:none"><div id="wechat" style="display:inline-block"><img id="wechat_qr" src="/img/wechat_pay.png" alt="MrBird WeChat Pay"></div><div id="alipay" style="display:inline-block"><img id="alipay_qr" src="/img/ali_pay.png" alt="MrBird Alipay"></div></div></div><style>#QR img{width:auto;margin:.8em 1em 0 1em}</style></div><div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者：</strong> MrBird</li><li class="post-copyright-link"><strong>本文链接：</strong> <a href="http://mrbird.cc/Nginx install deploy.html" title="Nginx安装与部署">http://mrbird.cc/Nginx install deploy.html</a></li><li class="post-copyright-license"><strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li></ul></div><footer class="post-footer"><div class="post-tags" style="margin-bottom:1.3rem"><a href="/tags/Nginx/" rel="tag"># Nginx</a></div><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/Spring-Boot使用thymeleaf.html" rel="next" title="Spring Boot中使用thymeleaf"><i class="fa fa-chevron-left"></i> Spring Boot中使用thymeleaf</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"><a href="/Nginx basic config.html" rel="prev" title="Nginx的基本配置">Nginx的基本配置 <i class="fa fa-chevron-right"></i></a></div></div></footer></article><hr><div id="container"></div><div class="post-spread"><div id="comment-div"></div><style>.valine .vlist{margin-bottom:3rem}.valine .vwrap .vcontrol .col.col-60{text-align:left}.valine .vlist .vcard .vhead,.valine .vlist .vcard section .vfooter{text-align:left}.valine .vlist .vcard section{padding-bottom:.5rem!important}.vname{color:#42b983!important}.valine .vinfo .col{text-align:left;margin-left:-27rem}div#comment-div{margin-bottom:-8rem}.valine .vlist .vcard .vcontent .code,.valine .vlist .vcard .vcontent code,.valine .vlist .vcard .vcontent pre{background:#fbfbfb}.valine .vlist .vcard .vcontent a{color:#42b983}.valine .vlist .vcard .vimg{border-radius:3px}.valine .vbtn{border-radius:2px;padding:.3rem 1.25rem}.valine .vbtn:active,.valine .vbtn:hover{color:#42b983;border-color:#42b983;background-color:#fff}.valine .vwrap .vheader .vinput:focus{border-bottom-color:#42b983}.valine .vlist .vcard .vcontent.expand:before{background:-webkit-gradient(linear,left top,left bottom,from(hsla(0,0%,100%,0)),to(hsla(0,0%,100%,.2)));background:linear-gradient(180deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.2))}.valine .vlist .vcard .vcontent.expand:after{content:"点击展开";font-size:.4rem;text-align:right;left:-1rem;background:hsla(0,0%,100%,.2)}.valine .vlist .vcard section .vfooter .vat{color:#b3b3b3}.valine .vlist .vcard section .vfooter .vat:hover{color:#42b983}.vcontent img{margin:0}.valine .info{display:none}</style><script type="text/javascript" src="/js/av.min.js"></script><script type="text/javascript" src="/js/Valine.min.js"></script><script type="text/javascript" src="/js/activate-power-mode.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,document.body.addEventListener("input",POWERMODE),new Valine({el:"#comment-div",notify:!1,verify:!0,appId:"SMcDFP1bN1jgb9Lo8JmtICHm-gzGzoHsz",appKey:"dH4nrUrt3V5XiJiI6Qyejnbi",placeholder:"",path:window.location.pathname,avatar:"monsterid",guest_info:["nick","mail","link"]});var chicken='<a href="#"><img src="https://image.uisdc.com/wp-content/uploads/2018/06/uisdc-chat-chicken.gif" class="checken"></a>';$("#comment-div").prepend(chicken)</script></div></div><script>var $bqinline=$("img[alt='bq-inline']");$bqinline.css({width:"2.3rem",height:"2.3rem",display:"inline","vertical-align":"text-bottom"})</script></div><div class="comments" id="comments"></div></div><aside id="sidebar" class="sidebar" onselectstart="return!1"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">Contents</li><li class="sidebar-nav-overview" data-target="site-overview">Site Preview</li></ul><section class="site-overview sidebar-panel"><div class="sidebar-sticky sticky"><div itemscope itemtype="http://schema.org/Person"><div class="author__avatar"><img src="/images/blogImage.jpg" class="author__avatar" alt="MrBird" itemprop="image"></div><div class="author__content"><h3 class="author__name" itemprop="name">MrBird's Blog</h3><p class="author__bio" itemprop="description">A simple blog, code repository, just keep blogging</p></div><div class="author__urls-wrapper"><button class="btn btn--inverse">Follow</button><ul class="author__urls social-icons"><li><a href="http://map.baidu.com/?newmap=1&s=s%26wd%3D%E7%A6%8F%E5%B7%9E%E5%B8%82%26c%3D300&from=alamap&tpl=mapcity" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-map-marker" aria-hidden="true"></i>&nbsp;&nbsp;FuZhou,CN</a></li><li><a href="https://love.mrbird.cc" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-diamond" aria-hidden="true"></i>&nbsp;&nbsp;Love</a></li><li><a href="https://cloud.mrbird.cn" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-chain" aria-hidden="true"></i>&nbsp;&nbsp;FEBS</a></li><li><a href="/atom.xml" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-rss" aria-hidden="true"></i>&nbsp;&nbsp;RSS</a></li><li><a href="https://gitee.com/mrbirdd" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-codepen" aria-hidden="true"></i>&nbsp;&nbsp;Gitee</a></li><li><a href="https://github.com/wuyouzhuguli" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-github-alt" aria-hidden="true"></i>&nbsp;&nbsp;GitHub</a></li><li><a href="javascript:;" class="popup-trigger"><i class="fa fa-fw fa-search" aria-hidden="true"></i>&nbsp;&nbsp;Search</a></li></ul></div></div></div><script>var $urls=$(".author__urls").find("a");$urls.each(function(){var o=$(this);o.mouseenter(function(){o.css({color:"#414547"})}),o.mouseleave(function(){o.css({color:""})})})</script></section><section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#下载Nginx"><span class="nav-number">1.</span> <span class="nav-text">下载Nginx</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Nginx编译与安装"><span class="nav-number">2.</span> <span class="nav-text">Nginx编译与安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Nginx的启停"><span class="nav-number">3.</span> <span class="nav-text">Nginx的启停</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx常用命令"><span class="nav-number">3.1.</span> <span class="nav-text">Nginx常用命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx启动"><span class="nav-number">3.2.</span> <span class="nav-text">Nginx启动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx停止"><span class="nav-number">3.3.</span> <span class="nav-text">Nginx停止</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx重启"><span class="nav-number">3.4.</span> <span class="nav-text">Nginx重启</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常见问题"><span class="nav-number">4.</span> <span class="nav-text">常见问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#缺少依赖库"><span class="nav-number">4.1.</span> <span class="nav-text">缺少依赖库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其他问题"><span class="nav-number">4.2.</span> <span class="nav-text">其他问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#附录"><span class="nav-number">5.</span> <span class="nav-text">附录</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#configure开关选项"><span class="nav-number">5.1.</span> <span class="nav-text">configure开关选项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#configure先決条件选项"><span class="nav-number">5.2.</span> <span class="nav-text">configure先決条件选项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#configure模块选项"><span class="nav-number">5.3.</span> <span class="nav-text">configure模块选项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其它configure选项"><span class="nav-number">5.4.</span> <span class="nav-text">其它configure选项</span></a></li></ol></li></ol></div></div></section></div></aside></div></main><footer id="footer" class="footer" onselectstart="return!1"><div class="footer-inner"><div class="copyright">&copy; 2016 - <span itemprop="copyrightYear">2019</span>&nbsp;&nbsp; <span class="author" itemprop="copyrightHolder">MrBird</span>&nbsp;&nbsp;|<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>&nbsp;&nbsp;UV&nbsp;<span class="busuanzi-value" id="busuanzi_value_site_uv" style="cursor:pointer" title="统计开始时间：2019年7月5日"></span> &nbsp;&nbsp;PV&nbsp;<span class="busuanzi-value" id="busuanzi_value_site_pv" style="cursor:pointer" title="统计开始时间：2019年7月5日"></span></div></div></footer><div class="back-to-top"><span style="font-family:'Source Sans Pro','Helvetica Neue',Arial,sans-serif;font-size:1.2em;font-weight:600">TOP</span></div></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script><script type="text/javascript">function proceedsearch(){$("body").append('<div class="search-popup-overlay local-search-pop-overlay"></div>').css("overflow","hidden"),$(".search-popup-overlay").click(onPopupClose),$(".popup").toggle();var t=$("#local-search-input");t.attr("autocapitalize","none"),t.attr("autocorrect","off"),t.focus()}var isfetched=!1,isXml=!0,search_path="search.xml";0===search_path.length?search_path="search.xml":search_path.endsWith("json")&&(isXml=!1);var path="/"+search_path,onPopupClose=function(t){$(".popup").hide(),$("#local-search-input").val(""),$(".search-result-list").remove(),$("#no-result").remove(),$(".local-search-pop-overlay").remove(),$("body").css("overflow","")},searchFunc=function(t,e,o){"use strict";$("body").append('<div class="search-popup-overlay local-search-pop-overlay"><div id="search-loading-icon"><i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i></div></div>').css("overflow","hidden"),$("#search-loading-icon").css("margin","20% auto 0 auto").css("text-align","center"),$.ajax({url:t,dataType:isXml?"xml":"json",async:!0,success:function(t){isfetched=!0,$(".popup").detach().appendTo(".header-inner");var n=isXml?$("entry",t).map(function(){return{title:$("title",this).text(),content:$("content",this).text(),url:$("url",this).text()}}).get():t,r=document.getElementById(e),s=document.getElementById(o),a=function(){var t=r.value.trim().toLowerCase(),e=t.split(/[\s\-]+/);e.length>1&&e.push(t);var o=[];if(t.length>0&&n.forEach(function(n){function r(e,o,n,r){for(var s=r[r.length-1],a=s.position,i=s.word,l=[],h=0;a+i.length<=n&&0!=r.length;){i===t&&h++,l.push({position:a,length:i.length});var p=a+i.length;for(r.pop();0!=r.length&&(s=r[r.length-1],a=s.position,i=s.word,p>a);)r.pop()}return c+=h,{hits:l,start:o,end:n,searchTextCount:h}}function s(t,e){var o="",n=e.start;return e.hits.forEach(function(e){o+=t.substring(n,e.position);var r=e.position+e.length;o+='<b class="search-keyword">'+t.substring(e.position,r)+"</b>",n=r}),o+=t.substring(n,e.end)}var a=!1,i=0,c=0,l=n.title.trim(),h=l.toLowerCase(),p=n.content.trim().replace(/<[^>]+>/g,""),u=p.toLowerCase(),f=decodeURIComponent(n.url),d=[],g=[];if(""!=l&&(e.forEach(function(t){function e(t,e,o){var n=t.length;if(0===n)return[];var r=0,s=[],a=[];for(o||(e=e.toLowerCase(),t=t.toLowerCase());(s=e.indexOf(t,r))>-1;)a.push({position:s,word:t}),r=s+n;return a}d=d.concat(e(t,h,!1)),g=g.concat(e(t,u,!1))}),(d.length>0||g.length>0)&&(a=!0,i=d.length+g.length)),a){[d,g].forEach(function(t){t.sort(function(t,e){return e.position!==t.position?e.position-t.position:t.word.length-e.word.length})});var v=[];0!=d.length&&v.push(r(l,0,l.length,d));for(var C=[];0!=g.length;){var $=g[g.length-1],m=$.position,x=$.word,w=m-20,y=m+80;w<0&&(w=0),y<m+x.length&&(y=m+x.length),y>p.length&&(y=p.length),C.push(r(p,w,y,g))}C.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hits.length!==e.hits.length?e.hits.length-t.hits.length:t.start-e.start});var T=parseInt("1");T>=0&&(C=C.slice(0,T));var b="";b+=0!=v.length?"<li><a href='"+f+"' class='search-result-title'>"+s(l,v[0])+"</a>":"<li><a href='"+f+"' class='search-result-title'>"+l+"</a>",C.forEach(function(t){b+="<a href='"+f+'\'><p class="search-result">'+s(p,t)+"...</p></a>"}),b+="</li>",o.push({item:b,searchTextCount:c,hitCount:i,id:o.length})}}),1===e.length&&""===e[0])s.innerHTML='<div id="no-result"><i class="fa fa-search fa-5x" /></div>';else if(0===o.length)s.innerHTML='<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>';else{o.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hitCount!==e.hitCount?e.hitCount-t.hitCount:e.id-t.id});var a='<ul class="search-result-list">';o.forEach(function(t){a+=t.item}),a+="</ul>",s.innerHTML=a}};r.addEventListener("input",a),$(".local-search-pop-overlay").remove(),$("body").css("overflow",""),proceedsearch()}})};$(".popup-trigger").click(function(t){t.stopPropagation(),isfetched===!1?searchFunc(path,"local-search-input","local-search-result"):proceedsearch()}),$(".popup-btn-close").click(onPopupClose),$(".popup").click(function(t){t.stopPropagation()}),$(document).on("keyup",function(t){var e=27===t.which&&$(".search-popup").is(":visible");e&&onPopupClose()})</script></body><script>$(function(){$("a").not(".nav-link,.cloud-tie-join-count,.ignore-href,.jstree-anchor").addClass("animsition-link")});var burst1=new mojs.Burst({left:0,top:0,radius:{5:40},children:{shape:"circle",fill:["red","cyan","orange"],fillOpacity:.8,radiusX:3.5,radiusY:3.5}});document.addEventListener("click",function(a){null==a.target.href&&"footer"!=a.target.className&&"copyright"!=a.target.className&&"author__urls social-icons"!=a.target.className&&"author__avatar"!=a.target.className&&"sidebar sidebar-active"!=a.target.className&&burst1.tune({x:a.pageX,y:a.pageY}).generate().replay()})</script><script type="text/javascript" src="/js/message.js"></script></html><!-- rebuild by neat -->